/** @format */

import '@babel/polyfill'
import Vue from 'vue'
import 'amfe-flexible/index.min.js'
import './publicUIConfig/UIUse'
import IconSvg from '@/components/IconSvg'

import router from './router/router'
import store from './store/store'

import App from './App.vue'
//导入全局时间过滤器，时间秒(s)格式化=> 00:00
import { formatDuring, formatYMD } from './utils/utils.js'
import VueQrcode from '@chenfengyuan/vue-qrcode'
import moment from 'moment'

import VeeValidate, { Validator } from 'vee-validate'
import zh_CN from 'vee-validate/dist/locale/zh_CN'
import VueI18n from 'vue-i18n'

//定义一个全局过滤器实现日期格式化
Vue.filter('datefmt', function(input, fmtstring) {
  // 使用momentjs这个日期格式化类库实现日期的格式化功能
  return moment(input).format(fmtstring)
})

Vue.use(VueI18n)
const i18n = new VueI18n({
  locale: 'zh_CN'
})
Vue.use(VeeValidate, {
  i18n,
  i18nRootKey: 'validation',
  dictionary: {
    zh_CN
  }
})

Validator.extend('mobile', {
  messages: {
    zh_CN: field => field + '必须是11位手机号码'
  },
  // getMessage: field => 'The ' + field + ' value is not truthy',
  getMessage: field => '请填写正确手机号码',
  validate: value => {
    return value.length === 11 && /^[1][0-9]{10}$/.test(value)
  }
})
Validator.extend('isIdCard', {
  getMessage: field => '请填写正确身份证号',
  validate: value => {
    return /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(
      value
    )
  }
})
Validator.extend('isBankCard', {
  getMessage: field => '请正确填写银行卡号',
  validate: value => {
    return /^(\d{16}|\d{19})$/.test(value)
  }
})

Vue.component(VueQrcode.name, VueQrcode)
Vue.component('IconSvg', IconSvg)

Vue.filter('formatDuring', formatDuring)
Vue.filter('formatYMD', formatYMD)
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
